package njClass.base
{
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	
	public class Common
	{	
		private var Root:DisplayObjectContainer;
		private var EventData:Array=new Array();
		
		public function Common(_root:DisplayObjectContainer){
			Root=_root;
		}
		
		public function $(_target:*,_eventType:String=null,callBackFunction:Function=null,addEvent:Boolean=true):*{
			if(_eventType!=null&&callBackFunction!=null){
				if(addEvent){
					_target.addEventListener(_eventType,callBackFunction);
					EventData.push({"Object":_target,"type":_eventType,"callback":callBackFunction});
				}else{
					var temp:Array=new Array();
					for(var i:* in EventData){
						if(EventData[i]["Object"]==_target&&EventData[i]["type"]==_eventType&&EventData[i]["callback"]==callBackFunction){
							_target.removeEventListener(_eventType,callBackFunction);
						}else{
							temp.push({"Object":EventData[i]["Object"],"type":EventData[i]["type"],"callback":EventData[i]["callback"]});
						}
					}
					EventData=temp;
				}
			}
			return _target;
		}
		
		public function Bind(_target:*,_name:String,_callBack:Function):void{
			var mark:*=_target[_name];
			_target.addEventListener(Event.ENTER_FRAME,ListenerValue);
			
			function ListenerValue(evt:Event):void{
				if(_target[_name]!=mark){
					mark=_target[_name];
					_callBack(mark);
				}
			}
		}
	}
}